package org.sendvox.freswitch.core;

import java.util.List;

import org.sendvox.freswitch.event.Event;

/**
 * The event command are used to subscribe on events from FreeSWITCH. You may
 * specify any number events on the same line, they should be separated with
 * space. The events are listed in the <a href="http://bit.ly/rtnpav">Event
 * List</a> page.
 * <p>
 * Examples: <br/><br/>
 * <source> event plain ALL </source> <br/>
 * <source>event plain CHANNEL_CREATE CHANNEL_DESTROY CUSTOM
 * conference::maintenance sofia::register sofia::expire </source> <br/>
 * <source>event xml ALL </source><br/>
 * <source>event json CHANNEL_ANSWER </source><br/>
 * </p>
 */
public interface EventCommand {

	/**
	 * Enable or disable events by class or all (plain or xml or json output
	 * format)
	 */
	public EventCommand type(Type eventType);

	/**
	 * list of events to log or all for all
	 */
	public EventCommand list(Event... events);

	public EventCommand custom(Object... customEvents);

	public EventCommand execute() throws CommandException;

	public List<Object> getEventList();;

	public enum Type {
		/**
		 * Enable or disable events by class or all (plain or xml or json output
		 * format)
		 * <p>
		 * <code>event plain <list of events to log or all for all></code>
		 * </p>
		 * The event command are used to subscribe on events from FreeSWITCH.
		 * You may specify any number events on the same line, they should be
		 * separated with space.
		 * <p>
		 * Reference: http://wiki.freeswitch.org/wiki/Event_Socket#event
		 * </p>
		 */
		EVENT_PLAIN("event plain"),

		/**
		 * Enable or disable events by class or all (plain or xml or json output
		 * format)
		 * <p>
		 * <code>event plain <list of events to log or all for all></code>
		 * </p>
		 * The event command are used to subscribe on events from FreeSWITCH.
		 * You may specify any number events on the same line, they should be
		 * separated with space.
		 * <p>
		 * Reference: http://wiki.freeswitch.org/wiki/Event_Socket#event
		 * </p>
		 */
		EVENT_JSON("event json"),

		/**
		 * Enable or disable events by class or all (plain or xml or json output
		 * format)
		 * <p>
		 * <code>event plain <list of events to log or all for all></code>
		 * </p>
		 * The event command are used to subscribe on events from FreeSWITCH.
		 * You may specify any number events on the same line, they should be
		 * separated with space.
		 * <p>
		 * Reference: http://wiki.freeswitch.org/wiki/Event_Socket#event
		 * </p>
		 */

		EVENT("event");

		private final String literal;

		private Type(String literal) {
			this.literal = literal;
		}

		public String getLiteral() {
			return literal;
		}

		public static Type fromLiteral(String literal) {
			for (Type type : values()) {
				if (type.literal.equalsIgnoreCase(literal)) {
					return type;
				}
			}
			return null;
		}
	}

}
